// components/diy/coupon/index.js
import { getCouponReceive } from '../../../api/user.js';
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    diyPramas:{
      type:Object
    },
    diyStyle:{
      type:Object
    },
    diyData:{
      type:Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    couponsList:{}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getCoupon:function(e){
      var that = this;
      var id = e.currentTarget.dataset.id;
      var index = e.currentTarget.dataset.index;
      var list = that.properties.diyData;
      //领取优惠券
      getCouponReceive({ couponId: id }).then(function (res) {
        list[index].is_use = true;
        app.Tips({ title: '领取成功' });
        that.setData({
          couponsList: list
        });
      },function(res){
        return app.Tips({title:res.msg});
      });
    },
  },
  ready(){
    this.setData({
      couponsList: this.properties.diyData
    });
  }
})
